import Vue from "vue";
import Layout from "@/layout";
import Router from "vue-router";
Vue.use(Router);

export const asyncRoutes = [
  {
    path: "/user",
    component: Layout,
    name: "系统管理",
    icon: "el-icon-collection",
    meta: {
      permission: "userList",
      roles: [1],
    },
    children: [
      {
        path: "list",
        component: () => import("@/views/system/user-list.vue"),
        name: "用户管理",
      },
    ],
  },
  {
    path: "/equipment",
    component: Layout,
    name: "设备管理",
    icon: "el-icon-collection",
    meta: {
      permission: "equipment",
      roles: [1, 2],
    },
    children: [
      {
        path: "list",
        component: () => import("@/views/system/equipment/index.vue"),
        name: "设备管理",
      },
    ],
  },
  {
    path: "/address",
    component: Layout,
    name: "地址信息管理",
    icon: "el-icon-collection",
    meta: {
      permission: "addressInfoManage",
      roles: [1, 2],
    },
    children: [
      {
        path: "list",
        name: "地址信息管理",
        component: () => import("@/views/address-info-manage/index.vue"),
      },
    ],
  },
  {
    path: "/main-config",
    component: Layout,
    name: "小程序首页管理",
    icon: "el-icon-collection",
    meta: {
      permission: "mainConfig",
      roles: [1, 2],
    },
    children: [
      {
        path: "add",
        name: "小程序首页轮播图",
        component: () => import("@/views/main-config/index.vue"),
      },
    ],
  },
  {
    path: "/instruction",
    component: Layout,
    name: "说明书",
    icon: "el-icon-collection",
    meta: {},

    children: [
      {
        path: "list",
        component: () => import("@/views/system/instructions/index.vue"),
        name: "说明书",
      },
    ],
  },
  { path: "*", redirect: "/404", hidden: true },
];
export const constantRoutes = [
  {
    path: "/redirect",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "/redirect/:path*",
        component: (resolve) => require(["@/views/redirect"], resolve),
      },
    ],
  },
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true,
  },
  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true,
  },
  {
    path: "/",
    component: Layout,
    redirect: "/home",
    icon: "el-icon-s-home",
    hidden: false,
    name: "主页",
    meta: {
      isHome: true,
    },
    children: [
      {
        path: "home",
        component: () => import("@/views/home"),
        name: "主页",
        meta: {
          affix: true,
        },
      },
    ],
  },
];
const createRouter = () =>
  new Router({
    scrollBehavior: () => ({ y: 0 }),
    routes: [...constantRoutes, ...asyncRoutes],
  });
const router = createRouter();
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher;
}
export default router;
